package com.xuxueli.commontdemo.controller;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.xuxueli.applyModules.entity.ExcelTemplate;
import com.xuxueli.applyModules.utils.testcharts.FieldValidation;
import com.xuxueli.commontdemo.commont.CommontService;
import com.xuxueli.commontdemo.entity.*;
import com.xuxueli.commontdemo.exception.ErrorException;
import com.xuxueli.commontdemo.listener.BasicExcelListener;
import com.xuxueli.commontdemo.service.ExportService;
import com.xuxueli.commontdemo.util.DateUtils;
import com.xuxueli.commontdemo.util.EasyExcelUtil;
import com.xuxueli.commontdemo.util.R;
import com.xuxueli.commontdemo.util.RandomUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @auther 你是最强者
 * @create 2022-01-18 15:40:19
 * @describe 测试导入excel
 */
@RestController
@RequestMapping("/testUploadExcel")
@Api(tags = "测试导入excel")
@Slf4j
public class TestUploadDataController {

    @Autowired
    private CommontService commontService;
    @Autowired
    private ExportService exportService;

    /**
     * 下载模板
     */
    @PostMapping(value = "/downExcel")
    @ApiOperation(value = "下载导入模板", notes = "下载导入模板")
    public R downLoadOwnerVehicleForm(HttpServletResponse response) {
        List<GraduaterNamePara> dateList = new ArrayList<>();
        try {
            EasyExcelUtil.writeExcel(response, dateList, GraduaterNamePara.class, "模板名字", "sheet1");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return R.ok("新增成功");
    }

    /**
     * 多个sheet导入毕业生信息，类型操作
     *
     * @param file
     * @param type:B代表本科生，Y代表研究生
     * @param delType:all清空所有，否则部分
     * @param importType:increase递增，否则先删后插
     * @return
     * @throws IOException
     */
    @PostMapping("/importGraduater")
    @ApiOperation(value = "单个sheet导入毕业生信息", notes = "单个sheet导入毕业生信息")
    public R importGraduater(@RequestPart(value = "file") MultipartFile file,
                             @RequestParam(value = "type") String type,
                             @RequestParam(value = "delType") String delType,
                             @RequestParam(value = "importType") String importType) throws IOException {
        if (ObjectUtils.isEmpty(file) || file.getSize() <= 0) {
            throw new ErrorException(500, "请上传相关的excel文件");
        }
        //递增处理
        if ("increase".equals(importType)) {
            List<UserManagerTemp> dataList = new ArrayList<>();
            List<ReadSheet> readSheetList = EasyExcel.read(file.getInputStream()).build().excelExecutor().sheetList();
            for (ReadSheet readSheet : readSheetList) {
                List<UserManagerTemp> userManagerTemps = EasyExcelUtil.readExcelBySheet(file.getInputStream(), UserManagerTemp.class, readSheet.getSheetNo());
                if (CollectionUtils.isNotEmpty(userManagerTemps)) {
                    dataList.addAll(userManagerTemps);
                }
            }
            if (CollectionUtils.isEmpty(dataList)) {
                throw new ErrorException(500, "上传文件为空");
            } else {
                String tempOwner = RandomUtil.getNumRandom();
                dataList.stream().forEach(item -> {
                    item.setTempOwner(tempOwner);
                });
                commontService.importGraduaterMoreSheet(dataList, tempOwner, type);
            }
            dataList.clear();//结束后销毁不用的资源

        } else {
            List<GraduaterNamePara> dataList = new ArrayList<>();
            List<ReadSheet> readSheetList = EasyExcel.read(file.getInputStream()).build().excelExecutor().sheetList();
            for (ReadSheet readSheet : readSheetList) {
                List<GraduaterNamePara> userManagerTemps = EasyExcelUtil.readExcelBySheet(file.getInputStream(), GraduaterNamePara.class, readSheet.getSheetNo());
                if (CollectionUtils.isNotEmpty(userManagerTemps)) {
                    dataList.addAll(userManagerTemps);
                }
            }
            if (CollectionUtils.isEmpty(dataList)) {
                throw new ErrorException(500, "请填写相关的上传数据");
            } else {
                commontService.batchGraduaterData(delType, type, dataList);
            }
            dataList.clear();//结束后销毁不用的资源
        }
        return R.ok("新增成功");
    }

    /**
     * 多个sheet导入毕业生
     *
     * @param file
     * @throws IOException
     */
    @PostMapping("/importGraduaterMoreSheet")
    @ApiOperation(value = "多个sheet导入毕业生", notes = "多个sheet导入毕业生")
    public R importGraduaterMoreSheet(@RequestPart(value = "file") MultipartFile file) throws IOException {
        if (ObjectUtils.isEmpty(file) || file.getSize() <= 0) {
            throw new ErrorException(500, "请上传相关的excel文件");
        }
        List<GraduaterNamePara> dataList = new ArrayList<>();
        List<ReadSheet> readSheetList = EasyExcel.read(file.getInputStream()).build().excelExecutor().sheetList();
        for (ReadSheet readSheet : readSheetList) {
            List<GraduaterNamePara> userManagerTemps = EasyExcelUtil.readExcelBySheet(file.getInputStream(), GraduaterNamePara.class, readSheet.getSheetNo());
            if (CollectionUtils.isNotEmpty(userManagerTemps)) {
                dataList.addAll(userManagerTemps);
            }
        }
        if (CollectionUtils.isEmpty(dataList)) {
            throw new ErrorException(500, "请填写相关的上传数据");
        } else {
            commontService.batchGraduaterData("all", null, dataList);
        }
        dataList.clear();//结束后销毁不用的资源
        return R.ok("新增成功");
    }


    /**
     * 根据角色id导入角色用户
     *
     * @param file
     * @param roleId
     * @param type
     * @param searchType
     * @return
     * @throws IOException
     */
    @PostMapping("/importRoleUser")
    @ApiOperation(value = "根据角色id导入角色用户", notes = "根据角色id导入角色用户")
    public R importRoleUser(@RequestPart(value = "file") MultipartFile file,
                            @RequestParam(value = "roleId") Long roleId,
                            @RequestParam(value = "type") String type,
                            @RequestParam(value = "searchType") String searchType
    ) throws IOException {
        if (ObjectUtils.isEmpty(file) || file.getSize() <= 0) {
            throw new ErrorException(500, "请上传相关的excel文件");
        }
        byte[] byteArr;
        try {
            byteArr = file.getBytes();
        } catch (IOException e) {
            throw new ErrorException(500, "文件格式转换异常");
        }
        InputStream inputStream = new ByteArrayInputStream(byteArr);
        List<UserManagerTemp> dataList = EasyExcelUtil.readExcel(inputStream, UserManagerTemp.class);
        if (CollectionUtils.isEmpty(dataList)) {
            throw new ErrorException(500, "请填写相关的上传数据");
        } else {
            String tempOwner = RandomUtil.getNumRandom();
            dataList.stream().forEach(item -> {
                item.setTempOwner(tempOwner);
            });
            commontService.importRoleUser(dataList, roleId, tempOwner, type, searchType);
        }
        dataList.clear();//结束后销毁不用的资源
        return R.ok("新增成功");
    }

    /**
     * 导入数据校验导出数据，暂不使用
     *
     * @param file
     * @param response
     * @return
     * @throws IOException
     */
    @PostMapping("/uploadExcelOnly")
    @ApiOperation(value = "导入数据校验导出数据", notes = "导入数据校验导出数据")
    public R uploadExcelOnly(@RequestPart(value = "file") MultipartFile file, HttpServletResponse response) throws IOException {
        if (ObjectUtils.isEmpty(file) || file.getSize() <= 0) {
            throw new ErrorException(500, "请上传相关的excel文件");
        }
        byte[] byteArr;
        try {
            byteArr = file.getBytes();
        } catch (IOException e) {
            throw new ErrorException(500, "文件格式转换异常");
        }
        InputStream inputStream = new ByteArrayInputStream(byteArr);
        List<GraduaterNamePara> dataList = EasyExcelUtil.readExcel(inputStream, GraduaterNamePara.class);
        for (GraduaterNamePara excelModel : dataList) {
            try {
                FieldValidation.validate(excelModel);
            } catch (Exception e) {
                String message = e.getMessage();
                if (StringUtils.isBlank(message)) {
                    message = e.toString();
                }
                excelModel.setMessage(message);
            }
        }
        boolean anyMatch = dataList.stream().anyMatch(items -> StringUtils.isNotBlank(items.getMessage()));
        if (anyMatch) {
            EasyExcelUtil.writeExcel(response.getOutputStream(), dataList, GraduaterNamePara.class, "测试");
        }
        dataList.clear();//结束后销毁不用的资源
        return R.ok("新增成功");
    }

    /**
     * 暂不使用
     *
     * @param file
     * @return
     * @throws IOException
     */
    @PostMapping(value = "/importBasic")
    public R importBasic(@RequestPart(value = "file") MultipartFile file) throws IOException {
        if (ObjectUtils.isEmpty(file) || file.getSize() <= 0) {
            throw new ErrorException(500, "请上传相关的excel文件");
        }
        List<GraduaterNamePara> dataList = new ArrayList<>();
        List<ReadSheet> readSheetList = EasyExcel.read(file.getInputStream()).build().excelExecutor().sheetList();
        for (ReadSheet readSheet : readSheetList) {
            BasicExcelListener basicExcelListener = new BasicExcelListener();
            EasyExcel.read(file.getInputStream(), GraduaterNamePara.class, basicExcelListener).headRowNumber(1).sheet(readSheet.getSheetNo()).doRead();
        }
        return R.ok("导入成功");
    }


    /**
     * 导出excel
     * @param params
     * @param response
     */
    @GetMapping(value = "export")
    public void export(@RequestParam Map<String, String> params, HttpServletResponse response) {
        try {
            log.info("报表-开始导出时间：{}", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now()));
            String beginTime = params.get("beginTime");// 开始时间
            String endTime = params.get("endTime");// 结束时间
            if (null == beginTime || "".equals(beginTime) ||
                    null == endTime || "".equals(endTime)) {// 时间条件必须输入
                response.getOutputStream().write("查询时间条件为空，无法进行导出操作！".getBytes("UTF-8"));
                response.getOutputStream().close();
                return;
            }

            // 告诉浏览器用什么软件可以打开此文件
            response.setHeader("content-Type", "application/vnd.ms-excel");
            // 下载文件的默认名称
            String filename = "" + DateUtils.formatDate(DateUtils.getCurrentData(), "yyyyMMddHHmmss") + ".xlsx";
            response.setHeader("Content-Disposition", "attachment;filename=" + filename);
            String sheetName = "";
            List<XXX> list = new ArrayList<>();
            //todo:自己的业务逻辑处理代码
            //该方法是将excel写到本地。咱们是通过接口传到前端页面，所以这个方法不需要。
            // EasyExcel.write(filename,XXX.class).sheet(sheetName).doWrite(list);
            ServletOutputStream outputStream = response.getOutputStream();
            //新建ExcelWriter
            ExcelWriter excelWriter = EasyExcel.write(outputStream).build();
            //新建sheet
            WriteSheet sheet = EasyExcel.writerSheet(0, sheetName).head(XXX.class).build();

            //如果...，那么导出的EXCEL中不应该包含X这列
//            if (自己的逻辑判断条件) {
//                Set<String> excludeColumnFiledNames = new HashSet<String>();
//                excludeColumnFiledNames.add("X 要忽略的字段，跟上面XXX实体类中相同");
//                sheet.setExcludeColumnFiledNames(excludeColumnFiledNames);
//            }
            //写回给前端
            excelWriter.write(list, sheet);
            //关闭流
            excelWriter.finish();
            outputStream.flush();
            log.info("报表-结束导出时间：{}", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now()));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("导出报表，出现异常:", e);
        } finally {
            try {
                if (null != response.getOutputStream()) {
                    response.getOutputStream().close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 导出excel
     * @param response
     */
    @GetMapping(value = "exportExcel")
    public void exportExcel(HttpServletResponse response){
        List<BasicSysUserExcelData> exportList = new ArrayList<>();
        try {
            //设置头居中
            WriteCellStyle headWriteCellStyle = new WriteCellStyle();
            headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
            //设置内容居中
            WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
            contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
            HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            response.setCharacterEncoding("utf-8");
            String fileName = URLEncoder.encode("员工表信息", "UTF-8");
            response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
            EasyExcel.write(response.getOutputStream(), BasicSysUserExcelData.class)
                    .autoCloseStream(Boolean.FALSE)
                    .registerWriteHandler(horizontalCellStyleStrategy)
                    .sheet("员工表信息")
                    .doWrite(exportList);
        } catch (Exception e) {
            response.reset();
            response.setContentType("application/json");
            response.setCharacterEncoding("utf-8");
            System.out.println("导出失败");
        }

    }

    /**
     * 下载模板
     * @param response
     * @throws IOException
     */
    @GetMapping("/downloadImportFileSubject")
    public void downloadImportFileSubject(HttpServletResponse response) throws IOException {
        List<OutEvalTopic> list = new ArrayList<>();
        list.add(new OutEvalTopic());
        EasyExcelUtil.download(response, list, "模板");
    }

    /**
     * 导入数据
     * @param file
     * @return
     * @throws IOException
     */
    @RequestMapping("/importExcelSubject")
    public R importExcelSubject(MultipartFile file) throws IOException {
        List<OutEvalTopic> list = EasyExcelUtil.read(file.getInputStream(),OutEvalTopic.class);
        //outEvalDeclareService.saveBatchTopic(list);
        return R.ok().put("data",list);
    }


    /**
     * 用户洞察中心App导出
     * @param request
     * @param response
     */
    @GetMapping("/downLoadApp")
    public void downLoadApp(HttpServletRequest request, HttpServletResponse response) {
        exportService.downLoadInsightApp(response);
    }

    /**
     * 测试成功
     * @param response
     * @throws IOException
     */
    @ApiOperation("Excel数据导出接口")
    @GetMapping(value = "/exports")
    public void exports(HttpServletResponse response) throws IOException {
        OutputStream outputStream = response.getOutputStream();
        String time = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss").format(new Date());
        //添加响应头信息
        response.setHeader("Content-disposition", "attachment; filename=" + "contract"+time+".xlsx");
        //设置类型
        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
        //设置头
        response.setHeader("Pragma", "No-cache");
        //设置头
        response.setHeader("Cache-Control", "no-cache");
        //设置日期头
        response.setDateHeader("Expires", 0);
        //获取总数据量
        Integer count = 10001;
        //如果总数据量多余1万，分页导出
        if(count>10000){
            //每页多少个
            int max=1000;
            //必须放到循环外，否则会刷新流
            ExcelWriter excelWriter= EasyExcel.write(outputStream).build();
//            List<ExcelTemplate> exportLists = new ArrayList<>(10001);
//            for (int i = 0; i <= exportLists.size()/max; i++) {
//                Integer fromSize = max * i;
//                Integer toSize = max * (i + 1);
//                if (toSize > exportLists.size()) {
//                    toSize = exportLists.size();
//                }
//                List<ExcelTemplate> excelTemplates = exportLists.subList(fromSize, toSize);
//            }
            int pageIndex = 1;
            for (int i=0;i<(count/max)+1;i++){
                List<ExcelTemplate> exportList = new ArrayList<>(10001);
                for (int j = 0; j <=10001 ; j++) {
                    ExcelTemplate excelTemplate = new ExcelTemplate();
                    excelTemplate.setX0("你好厉害");
                    excelTemplate.setX1(String.format("%d",j));
                    excelTemplate.setTimeNow(new Date());
                    excelTemplate.setDoubleData(18.89d);
                    exportList.add(excelTemplate);
                }
                List<ExcelTemplate> areaVo = exportList.stream()
                        .skip(max * (pageIndex - 1))
                        .limit(max).collect(Collectors.toList());
                pageIndex++;
                WriteSheet writeSheet = EasyExcel.writerSheet(i, "合同" + (i + 1)).head(ExcelTemplate.class)
                        .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).build();
                excelWriter.write(areaVo,writeSheet);
            }
            //刷新流
            excelWriter.finish();
        }else {
            List<ExcelTemplate> exportList = new ArrayList<>(16);
            for (int j = 0; j <=16 ; j++) {
                ExcelTemplate excelTemplate = new ExcelTemplate();
                excelTemplate.setX0("你好厉害");
                excelTemplate.setX1(String.format("%d",j));
                excelTemplate.setTimeNow(new Date());
                excelTemplate.setDoubleData(18.89d);
                exportList.add(excelTemplate);
            }
            ExcelTemplate excelTemplate = new ExcelTemplate();
            excelTemplate.setTimeNow(new Date());
            excelTemplate.setDoubleData(18.89d);
            exportList.add(excelTemplate);
            EasyExcel.write(outputStream,ExcelTemplate.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).sheet("合同").doWrite(exportList);
        }
        outputStream.flush();
        response.getOutputStream().close();
    }

    /**
     * 验证异常捕捉
     * 开启新的事务
     * @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRES_NEW)
     * 事务异常回滚
     * @Transactional(rollbackFor = Exception.class)
     * 手动执行事务
     * @TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
     * 该隔离级别表示不以事务运行
     * @Transactional(propagation = Propagation.NOT_SUPPORTED)
     * @return
     */
//    @PostMapping("/test/err/getException")
//    public ResultObject getException(@RequestBody Domain people) {
//        return testService.getException(people);
//    }

//    /**
//     * 报核提醒打印
//     * @return
//     * @throws Exception
//     */
//    @GetMapping(value = "/printDcrHead/{emsNo}/{dcrTimes}")
//    public ResponseEntity printDcrHead(@PathVariable String emsNo, @PathVariable Integer dcrTimes, @RequestParam(required = false,value = "vaule") String vaule) throws Exception {
//        String templateName = "dcrExportTemplate.xlsx";
//        String fileName = UUID.randomUUID().toString() + ".pdf";
//        List<EmsDcrHeadPrintDto> emsDcrHeadDtoList = testService.printDcrHead(emsNo,dcrTimes);
//        String exportFileName = "";
//        if (emsDcrHeadDtoList.size() > 0) {
//            exportFileName = testService.exportDcrHeadExcel(emsDcrHeadDtoList,fileName, templateName,"我来了");
//        }else{
//            return ResponseEntity.noContent().build();
//        }
//        HttpHeaders h = new HttpHeaders();
//        h.setContentDispositionFormData("attachment", URLEncoder.encode("年度核销打印.pdf","UTF-8"));
//        h.add(HttpHeaders.CONTENT_TYPE, "application/pdf;charset=ISO8859-1");
//        return ResponseEntity.ok().headers(h).body(new InputStreamResource(new FileInputStream(new File(exportFileName))));
//    }

    /**
     * 测试下载
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "测试下载")
    @GetMapping("/downloadBills/{billListNos}")
    public ResponseEntity downloadBills(@RequestHeader(value = "reqId", required = false) String batchid, @PathVariable List<String> billListNos) throws Exception {
        ResponseEntity responseEntity = ResponseEntity.noContent().build();
        try {
            String fileName = "E:\\测试包\\dcrExportTemplate.xlsx";
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            String newFileName = "我来了" + "(" + "love" + ")_" + sdf.format(new Date()) + ".xlsx";
            HttpHeaders h = new HttpHeaders();
            h.setContentDispositionFormData("attachment", URLEncoder.encode(newFileName, "UTF-8"));
            h.add(HttpHeaders.CONTENT_TYPE, "application/xlsx;charset=ISO8859-1");
            responseEntity = ResponseEntity.ok().headers(h).body(new InputStreamResource(new FileInputStream(new File(fileName))));
        } catch (ErrorException err) {
            err.printStackTrace();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return responseEntity;
    }


//    /**
//     * @param exportParam
//     * （{
//     * "exportColumns":{"cavMark": "E2325B0A0008_02_01","codeTS": "","copGNo": "","differQty": "","excludeZero": "1","gNo": ""},
//     * "name": "HxPriceAvg-表头",
//     * "header":[
//     *   {
//     *     "key": "copGNo",
//     *     "value": "料号"
//     *   },
//     *   {
//     *     "key": "gNo",
//     *     "value": "备案序号"
//     *   }
//     * ]
//     * }）
//     * @throws Exception
//     */
//    @ApiOperation("Excel数据导出接口")
//    @PostMapping(value = "/export")
//    public ResponseEntity export(@Valid @RequestBody PeopleExportParam exportParam) throws Exception{
//        List<People> peopleList = testService.getList(exportParam.getExportColumns());
//        if(peopleList.size() < 1){
//            return ResponseEntity.noContent().build();
//        }
//        StringBuilder excelName = new StringBuilder();
//        excelName.append("进");
//        excelName.append("口清单汇总");
//        byte[] result = testService.getExport(peopleList, exportParam.getHeader(), excelName.toString());
//        excelName.append(".xlsx");
//        HttpHeaders h = new HttpHeaders();
//        h.setContentDispositionFormData("attachment", URLEncoder.encode(excelName.toString(),"UTF-8"));
//        h.setContentType(MediaType.APPLICATION_OCTET_STREAM);
//        return new ResponseEntity(result, h, HttpStatus.OK);
//    }
//
//    /**
//     * 核注清单打印
//     *
//     * @return
//     * @throws Exception
//     */
//    @ApiOperation(value = "核注清单打印")
//    @GetMapping("/printBill/{billType}/{printType}/{billListNos}")
//    public ResponseEntity printBill(@PathVariable String billType, @PathVariable String printType, @PathVariable List<String> billListNos) throws Exception {
//        Map<String, String> mapFile = testService.printBill(billType, printType, billListNos);
//        String returnFile = mapFile.get("returnFile");
//        String returnFileName = mapFile.get("returnFileName");
//        HttpHeaders h = new HttpHeaders();
//        h.setContentDispositionFormData("attachment", URLEncoder.encode(returnFileName,"UTF-8"));
//        h.add(HttpHeaders.CONTENT_TYPE, "application/pdf;charset=ISO8859-1");
//        return ResponseEntity.ok().headers(h).body(new InputStreamResource(new FileInputStream(new File(returnFile))));
//    }
//
//    /**
//     * 核注清单下载
//     *
//     * @return
//     * @throws Exception
//     */
//    @ApiOperation(value = "核注清单下载")
//    @GetMapping("/downloadBill/{billType}/{billListNos}")
//    public ResponseEntity downloadBill(@PathVariable String billType, @PathVariable List<String> billListNos) throws Exception {
//        String fileName = testService.downloadBill(billType,billListNos);
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
//        String newFileName ="("+"tedtdrrf"+")_"+sdf.format(new Date()) +".xlsx";
//        HttpHeaders h = new HttpHeaders();
//        h.setContentDispositionFormData("attachment", URLEncoder.encode(newFileName,"UTF-8"));
//        h.add(HttpHeaders.CONTENT_TYPE, "application/xlsx;charset=ISO8859-1");
//        return ResponseEntity.ok().headers(h).body(new InputStreamResource(new FileInputStream(new File(fileName))));
//    }


}